#include <iostream>

/*单例模式中的饿汉模式：以空间换时间,程序运行后直接进行初始化*/
class SingHungry
{
private:
    static SingHungry _hungry;

public:
    int _data;

private:
    SingHungry()
        : _data(99)
    {
        std::cout << "单例对象中的饿汉模式构造" << std::endl;
    }
    SingHungry(const SingHungry &hungry) = delete;
    ~SingHungry() {}

public:
    static SingHungry &getSingHungry()
    {
        return _hungry;
    }
    int getData()
    {
        return _data;
    }
};
SingHungry SingHungry::_hungry;

/*单例模式中的懒汉模式：使用时才会初始化，同时在C++11之后static有了线程安全*/
class SingLazy
{
public:
    int _data;

private:
    SingLazy()
        : _data(99)
    {
        std::cout << "单例对象中的懒汉模式构造" << std::endl;
    }
    SingLazy(const SingLazy &lazy) = delete;
    SingLazy operator=(const SingLazy &lazy) = delete;
    ~SingLazy() {}

public:
    static SingLazy& getSingLazy()
    {
        static SingLazy _lazy;
        return _lazy;
    }
    int getData()
    {
        return _data;
    }
};

int main()
{
    // std::cout << SingHungry::getSingHungry().getData() << std::endl;
    std::cout << SingLazy::getSingLazy().getData() << std::endl;

    return 0;
}